_require local "../../../../basis.smi"
_require local "../../../../smlformat-lib.smi"
_require local "../../../extensions/debug/main/Bug.smi"
_require "../../../extensions/usererror/main/UserError.ppg.smi"
_require "../../../libs/toolchain/main/Filename.smi"
_require local "../../../libs/util/main/TermFormat.smi"
_require "../../../compilePhases/nameevaluation/main/NameEvalEnv.ppg.smi"
(* _require "../../../compilerIRs/absyn/main/InterfaceName.ppg.smi" *)
_require "../../../compilerIRs/idcalc/main/IDCalc.ppg.smi"
_require "../../../compilerIRs/absyn/main/InterfaceName.ppg.smi"
_require "../../../compilePhases/elaborate/main/Elaborator.smi"

structure TopData =
struct

  datatype stopAt =
      SyntaxCheck                   (* run until syntax check is completed. *)
    | ErrorCheck                    (* run until error check is completed. *)
    | NameRef                       (* run until name reference is completed. *)
    | NoStop

  type options =
      {
        stopAt: stopAt,                         (* compile will stop here. *)
        baseFilename: Filename.filename option, (* base name for file search *)
        loadPath: InterfaceName.source list,    (* path for file search *)
        loadMode: InterfaceName.file_load_mode, (* load mode *)
        outputWarnings: UserError.errorInfo list -> unit,
        defaultInterface: Filename.filename -> Filename.filename
      }

  type toplevelContext =
      {
        topEnv: NameEvalEnv.topEnv,
        version: IDCalc.version,
        fixEnv: Elaborator.fixEnv,
        builtinDecls: IDCalc.icdecl list
      }
  type newContext =
      {
        topEnv: NameEvalEnv.topEnv,
        fixEnv: Elaborator.fixEnv
      }

  datatype result =
      STOPPED                                   (* aborted due to stopAt. *)
    | RETURN of newContext * Filename.filename  (* compile completed *)

  val debugPrint : string -> unit
  val printStopAt : stopAt -> unit
  val printFileName : Filename.filename -> unit
  val printResult : result -> unit
  val printOptions : options -> unit

  exception UnsupportedPointerSize of int
  exception IllegalBuiltin of Filename.filename
end
